Skip to content

CMR-11422: Add parameter to only allow validate keyword usage by provider (Enforcement list) - #2490

Merged
eudoroolivares2016 merged 14 commits into
masterfrom
CMR-11422
Sep 4, 2026
Merged

CMR-11422: Add parameter to only allow validate keyword usage by provider (Enforcement list)#2490
eudoroolivares2016 merged 14 commits into
masterfrom
CMR-11422

Conversation

@eudoroolivares2016

@eudoroolivares2016 eudoroolivares2016 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Overview

What is the objective?

Adding a parameter store to be able to prevent providers in an enforced list e.g. the esdis providers +- to no longer be able to use the validate-keyword: false header which has allowed unsearchable metadata into the system

There is a temporary carveout for the KMS API itself until we resolve the cache delay issue either by removing the CMR cache entirely or having KMS issue a cache refresh to CMR CMR-11524.

What are the changes?

Added a new parameter store that is a comma sep list, pulled that into the conditional logic of the validate-keyword value, refactoring KMS lookup function.

What areas of the application does this impact?

CMR ingest and metadata validation

Testing

  1. Create multiple providers if in SIT, set this parameter store in the ingest-app redeploy CMR
  2. Ensure that the providers on that list are unable to use validate-keyword header. If they do it will always resolve to being true. Ensure that the KMS API if correcting a metadata keyword issue is still able to make sure of it. (SIT only testing possible) https://cmr.sit.earthdata.nasa.gov/kms/metadata_correction
  3. Delete local keyword cache. Ensure that running curl -i -X POST -H "Authorization: mock-echo-system-token" http://localhost:3006/caches/refresh/kms regenerates all the caches as it does on main

Required Checklist

  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors in changed files are corrected
  • I have commented my code, particularly in hard-to-understand areas
  • I have made changes to the documentation (if necessary)
  • My changes generate no new warnings

Additional Checklist

  • I have removed unnecessary/dead code and imports in files I have changed
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • reduced number of system state resets by updating fixtures. Ex) (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

@eudoroolivares2016 eudoroolivares2016 changed the title Cmr 11422 CMR-11422: Aug 31, 2026
@eudoroolivares2016 eudoroolivares2016 changed the title CMR-11422: CMR-11422: Add parameter to only allow validate keyword usage by provider (exclusive list) Aug 31, 2026
@eudoroolivares2016
eudoroolivares2016 marked this pull request as ready for review August 31, 2026 16:52
@eudoroolivares2016 eudoroolivares2016 changed the title CMR-11422: Add parameter to only allow validate keyword usage by provider (exclusive list) CMR-11422: Add parameter to only allow validate keyword usage by provider (Enforcement list) Aug 31, 2026
(defn- generate-lookup-by-related-urls-map
"Create a map with the related url comparison map as keys to the UUID for that related url."
[gcmd-keywords-map]
(def gkm gcmd-keywords-map)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove debugging code.

Comment thread common-app-lib/src/cmr/common_app/services/kms_lookup.clj Outdated
Comment thread common-app-lib/src/cmr/common_app/services/kms_lookup.clj
Comment thread ingest-app/src/cmr/ingest/api/collections.clj Outdated
Comment thread ingest-app/src/cmr/ingest/config.clj Outdated
Example \"PROV1,PROV2\", would enforce keyword validation for PROV1 and PROV2.
If no providers should have keyword validation enforced, set to an empty array."
{:default []
:parser #(map (comp keyword string/trim) (string/split % #","))})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the CMR_KEYWORD_ENFORCED_PROVIDERS parameter store does not exist an empty array [] is returned. What if an empty string is defined in the parameter store ""

When the input % is an empty string "", this snippet will evaluate to a list containing a single empty keyword: (:).

Step-by-Step Breakdown
(string/split "" #",")
Splitting an empty string does not return an empty list. It returns a vector containing the empty string itself: [""].
(string/trim "")
Trimming an empty string simply returns the empty string: "".
(keyword "")
Passing an empty string to keyword produces an empty keyword printed as : in Clojure.

Why This Is Dangerous
An empty keyword (:) is valid Clojure syntax, but it is rarely intended.
It can cause silent bugs because:It evaluates to truthy in conditional checks.
It will not match a proper keyword like :provider-id.It consumes a tiny amount of memory in the keyword table that cannot be garbage collected.

;; Option 1: Remove blanks before processing (Recommended)
(->> (string/split % #",")
(remove string/blank?)
(map (comp keyword string/trim)))
;; Input: "" => Output: ()

;; Option 2: Use keep to filter out blanks during the map step
(keep #(when-not (string/blank? %)
(keyword (string/trim %)))
(string/split % #","))
;; Input: "" => Output: ()

@eereiter eereiter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of small changes

@codecov-commenter

codecov-commenter commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.93%. Comparing base (682556e) to head (e7832d2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
ingest-app/src/cmr/ingest/config.clj 33.33% 9 Missing and 1 partial ⚠️
ingest-app/src/cmr/ingest/api/collections.clj 83.33% 2 Missing and 1 partial ⚠️
...app-lib/src/cmr/common_app/services/kms_lookup.clj 92.59% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2490      +/-   ##
==========================================
- Coverage   57.95%   57.93%   -0.03%     
==========================================
  Files        1074     1074              
  Lines       74707    74649      -58     
  Branches     2188     2176      -12     
==========================================
- Hits        43294    43245      -49     
- Misses      29365    29368       +3     
+ Partials     2048     2036      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eudoroolivares2016
eudoroolivares2016 force-pushed the CMR-11422 branch 2 times, most recently from 6662401 to 7a0e83e Compare September 2, 2026 16:44

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provider enforcement is bypassed by the mere presence of cmr-send-kms-metadata-fixer; the new tests even accept the value false. Nothing in get-validation-options authenticates that request header, so an enforced provider can set it and regain the normal validate-keywords=false path. Gate this carveout on trusted KMS caller identity rather than a client-supplied header, and add a spoofing regression.

Comment thread ingest-app/src/cmr/ingest/config.clj Outdated
:parser #(->> (string/split % #",")
(remove string/blank?)
(map string/trim))
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while I like this syntax, it is not the clojure way to put closing brackets on a new line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran it with cljfmt it found some other stuff in there

@eudoroolivares2016
eudoroolivares2016 merged commit 2fd729a into master Sep 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants